   var uploadAuth, uploadAddress, videoId;
   var uploader = new AliyunUpload.Vod({
        //阿里账号ID，必须有值 ，值的来源https://help.aliyun.com/knowledge_detail/37196.html
        userId:"",
        //上传到点播的地域， 默认值为'cn-shanghai',//eu-central-1,ap-southeast-1
        region:"",
        //分片大小默认1M，不能小于100K
        partSize: 1048576,
       //并行上传分片个数，默认5
        parallel: 5,
        //网络原因失败时，重新上传次数，默认为3
        retryCount: 3,
        //网络原因失败时，重新上传间隔时间，默认为2秒
        retryDuration: 2,
        // 开始上传
       'onUploadstarted': function (uploadInfo) {
           //console.log("onUploadStarted:" + uploadInfo.file.name + ", endpoint:" + uploadInfo.endpoint + ", bucket:" + uploadInfo.bucket + ", object:" + uploadInfo.object);
           uploader.setUploadAuthAndAddress(uploadInfo, uploadAuth, uploadAddress, videoId);
       },
       // 文件上传成功
       'onUploadSucceed': function (uploadInfo) {
           var $percent = '<span class="padding-10-0">文件：[' + uploadInfo.file.name +'] 上传状态：上传完成，保存并获取封面中..</span>'
           $('#upload-box .upload-percent').html($percent);
           //console.log("onUploadSucceed: " + uploadInfo.file.name + ", endpoint:" + uploadInfo.endpoint + ", bucket:" + uploadInfo.bucket + ", object:" + uploadInfo.object);
           $.ajax({
               type: 'POST',
               url: '../common/aliyun/uploadvod',
               data:{fileName: uploadInfo.file.name, fileSize: uploadInfo.file.size, videoId: uploadInfo.videoId},
               success: function(data){
                   if(data.code == 0){
                       $('#upload-box .upload-percent').html('');
                       var $html='<div class="upload-item" style="position:relative; display:inline-block;vertical-align: top;">'
                           + '<input type="hidden" name="vodId" value="'+ uploadInfo.videoId+'">'
                           + '<img src="'+data.result.fileCoverUrl+'" class="vodImg">'
                           + '<span class="glyphicon glyphicon-play-circle upload-play" style="height: 0px;width: 0px;left: -140px;top: 10px;font-size: 40px;color: #fff; cursor: pointer;"></span>'
                           + '<span class="label label-sm label-danger upload-del" style="position:absolute;cursor:pointer;right:6px;top:0;">'
                           + '<i class="ace-icon fa fa-times-circle bigger-120"></i>'
                           + '</span></div>';
                       $('#upload-box').prepend($html);
                   }else{
                       alert(data.msg);
                   }
               },
               error: function(res){
                   console.log(res);
               }
           })
       },
       // 文件上传失败
       'onUploadFailed': function (uploadInfo, code, message) {
           var $percent = '<span class="padding-10-0">文件：[' + uploadInfo.file.name +'] 上传状态：上传失败！ 失败原因：'+message+'</span>'
           $('#upload-box .upload-percent').html($percent);
           //console.log("onUploadFailed: file:" + uploadInfo.file.name + ",code:" + code + ", message:" + message);
       },
       // 文件上传进度，单位：字节
       'onUploadProgress': function (uploadInfo, totalSize, loadedPercent) {
           var $percent = '<span class="padding-10-0">文件：[' + uploadInfo.file.name +'] 上传状态：上传中.. 上传进度：'+Math.ceil(loadedPercent * 100)+'%</span>'
           $('#upload-box .upload-percent').html($percent);
           //console.log("onUploadProgress:file:" + uploadInfo.file.name + ", fileSize:" + totalSize + ", percent:" + Math.ceil(loadedPercent * 100) + "%");
       },
       // 上传凭证超时
       'onUploadTokenExpired': function (uploadInfo) {
           //console.log("onUploadTokenExpired");
           //实现时，根据uploadInfo.videoId调用刷新视频上传凭证接口重新获取UploadAuth
           getRefreshAuth();
       },
       //全部文件上传结束
       'onUploadEnd':function(uploadInfo){
            //console.log("onUploadEnd: uploaded all the files");
       }
   });
   
   $(function(){
       /*视频上传*/
       $('#upload-box').on('click', '.upload-btn',function(){$('#upload-box .upload-vod').click()});
       $('#upload-box').on('change', '.upload-vod', function (event) {
           var userData;
           for(var i=0; i<event.target.files.length; i++) {
               this.fileName = event.target.files[i].name;
               this.title = this.fileName.substring(0, this.fileName.lastIndexOf("."));
               getAuth(this.fileName, this.title);
               userData = '{"Vod":{"Title":"'+this.title+'"}}';
               uploader.addFile(event.target.files[i], null, null, null, userData);
           }
           uploader.startUpload();
       });
       
       /*视频删除*/
       $('#upload-box').on('click', '.upload-del', function (event) {
           var btnObj = $(this);
           var videoId = $(this).parent().find('input[name="vodId"]').val();
           $.ajax({
               type: 'POST',
               async:false,
               url: '../common/aliyun/removevod',
               data:{videoId:videoId},
               success: function(data){
                   if(data.code == 0){
                       btnObj.parent().remove();
                   }else{
                       alert(data.msg);
                   }
               },
               error: function(res){
                   console.log(res);
               }
           })
       });
       
       /*视频播放*/
       $('#upload-box').on('click', '.upload-play', function (event) {
           var videoId = $(this).parent().find('input[name="vodId"]').val();
           layer.open({
                type: 2,
                title: false,
                area: ['960px', '500px'],
                anim: 2,
                closeBtn: 1,
                shadeClose: true,
                shade: 0.6,
                content: ["../common/aliyun/playvod/"+videoId,'no']
            });
       });
   })
   
   /*获取上传凭证和上传地址*/
   function getAuth(fileName, title){
       $.ajax({
           type: 'GET',
           async:false,
           url: '../common/aliyun/getvodauth',
           data:{fileName:fileName, title:title},
           success: function(data){
               if(data.code == 0){
                   uploadAuth = data.result.uploadAuth;
                   uploadAddress = data.result.uploadAddress;
                   videoId = data.result.videoId;
               }else{
                   alert(data.msg);
               }
           },
           error: function(res){
               console.log(res);
           }
       })
   }
   
   /*获取上传刷新凭证*/
   function getRefreshAuth(){
       $.ajax({
           type: 'GET',
           url: '../common/aliyun/refreshvodauth',
           data:{videoId: uploadInfo.videoId},
           success: function(data){
               if(data.code == 0){
                   uploadAuth = data.result.uploadAuth;
                   //从点播服务刷新的uploadAuth,设置到SDK里
                   uploader.resumeUploadWithAuth(uploadAuth); 
               }else{
                   alert(data.msg);
               }
           },
           error: function(res){
               console.log(res);
           }
       })
   }